// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FastTupleTests.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Numerics
{
    using System;

    using Microsoft.Robotics.Numerics;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Fast Tuple tests
    /// </summary>
    [TestClass]
    public class FastTupleTests
    {
        /// <summary>
        /// Tests if TupleHoldsCorrectValuesWhenFieldsAreInitializedViaDefaultConstructor
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void TupleHoldsCorrectValuesWhenFieldsAreInitializedViaDefaultConstructor()
        {
            FastTuple<int, int> t2 = new FastTuple<int, int>(17, 23);
            Assert.IsTrue(t2.Item1 == 17);
            Assert.IsTrue(t2.Item2 == 23);

            FastTuple<int, int, int> t3 = new FastTuple<int, int, int>(17, 23, 29);
            Assert.IsTrue(t3.Item1 == 17);
            Assert.IsTrue(t3.Item2 == 23);
            Assert.IsTrue(t3.Item3 == 29);
        }

        /// <summary>
        /// Tests if TupleHoldsCorrectValuesWhenFieldsAreAssignedIndividually 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void TupleHoldsCorrectValuesWhenFieldsAreInitializedIndividually()
        {
            FastTuple<int, int> t2 = new FastTuple<int, int>();
            t2.Item1 = 17;
            t2.Item2 = 23;
            Assert.IsTrue(t2.Item1 == 17);
            Assert.IsTrue(t2.Item2 == 23);

            FastTuple<int, int, int> t3 = new FastTuple<int, int, int>();
            t3.Item1 = 17;
            t3.Item2 = 23;
            t3.Item3 = 29;
            Assert.IsTrue(t3.Item1 == 17);
            Assert.IsTrue(t3.Item2 == 23);
            Assert.IsTrue(t3.Item3 == 29);
        }

        /// <summary>
        /// Tests if TupleHoldsCorrectValuesWhenFieldsAreInitializedViaCopyConstructor 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void TupleHoldsCorrectValuesWhenFieldsAreInitializedViaCopyConstructor()
        {
            FastTuple<int, int> t21 = new FastTuple<int, int>(17, 23);
            FastTuple<int, int> t22 = new FastTuple<int, int>(t21);
            Assert.IsTrue(t22.Item1 == 17);
            Assert.IsTrue(t22.Item2 == 23);

            FastTuple<int, int, int> t31 = new FastTuple<int, int, int>(17, 23, 29);
            FastTuple<int, int, int> t32 = new FastTuple<int, int, int>(t31);
            Assert.IsTrue(t32.Item1 == 17);
            Assert.IsTrue(t32.Item2 == 23);
            Assert.IsTrue(t32.Item3 == 29);
        }

        /// <summary>
        /// Tests if EqualityHoldsWhenTuplesAreIdenticalAndFailsOtherwise 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void EqualityHoldsWhenTuplesAreIdenticalAndFailsOtherwise()
        {
            FastTuple<int, int> t21 = new FastTuple<int, int>(17, 23);
            FastTuple<int, int> t22 = new FastTuple<int, int>(17, 23);
            FastTuple<int, int> t23 = new FastTuple<int, int>(117, 23);
            FastTuple<int, int> t24 = new FastTuple<int, int>(17, 123);
            Assert.IsTrue(t21 == t22);
            Assert.IsTrue(t22 != t23);
            Assert.IsTrue(t22 != t24);

            FastTuple<int, int, int> t31 = new FastTuple<int, int, int>(17, 23, 29);
            FastTuple<int, int, int> t32 = new FastTuple<int, int, int>(17, 23, 29);
            FastTuple<int, int, int> t33 = new FastTuple<int, int, int>(117, 23, 29);
            FastTuple<int, int, int> t34 = new FastTuple<int, int, int>(17, 123, 29);
            FastTuple<int, int, int> t35 = new FastTuple<int, int, int>(17, 23, 129);
            Assert.IsTrue(t31 == t32);
            Assert.IsTrue(t32 != t33);
            Assert.IsTrue(t32 != t34);
            Assert.IsTrue(t32 != t35);
        }

        /// <summary>
        /// Tests if FastTupleEqualityDoesNotHoldWhenOtherObjectIsOfDifferentType 
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void FastTupleEqualityDoesNotHoldWhenOtherObjectIsOfDifferentType()
        {
            string strTest = "test";

            FastTuple<int, int> t2 = new FastTuple<int, int>(17, 23);
            Assert.IsTrue(!t2.Equals(strTest));

            FastTuple<int, int, int> t3 = new FastTuple<int, int, int>(17, 23, 29);
            Assert.IsTrue(!t3.Equals(t2));

            FastTuple<int, int, short> t3s = new FastTuple<int, int, short>(17, 23, 29);
            Assert.IsTrue(!t3.Equals(t3s));
        }
    }
}
